Passed
Push — master ( 0a8095...60f354 )
by hung
01:03
created

input.js ➔ ???   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
c 1
b 0
f 0
nc 4
dl 0
loc 20
rs 9.2
nop 2

1 Function

Rating   Name   Duplication   Size   Complexity  
A input.js ➔ ... ➔ ??? 0 3 1
1
const fs = require('fs')
2
const { join } = require('path')
3
const { Readable } = require('stream')
4
5
module.exports = (input, callback) => {
6
  if (typeof input === 'string') {
7
    const path = join(__dirname, '../', input)
8
    if (!fs.existsSync(path)) {
9
      console.error(`Cannot read file ${path}`)
10
      return
11
    }
12
    const html = fs.readFileSync(path, 'utf8')
13
    callback(html)
14
  } else if (input instanceof Readable) {
15
    input.on('data', chunk => {
16
      callback(chunk.toString())
17
    })
18
    input.on('error', err => {
19
      console.error(err)
20
    })
21
  } else {
22
    console.error('Invalid Input')
23
  }
24
}
25